﻿/**
* routeService - AngularJS module for web api management.
*
*
* Credits
* =======
*
* Copyright 2016 LonghronShen <LonghronShen@Hotmail.com>
*/

(function () {
    "use strict";

    /**
     * Config
     */
    var moduleName = 'ccp';
    var DEFAULT_ID = '__default';

    /**
     * Module
     */
    var module;
    try {
        module = angular.module(moduleName);
    } catch (err) {
        // named module does not exist, so create one
        module = angular.module(moduleName, []);
    }

    var baseUrl = "/";
    var AreaUrl = "http://api.sino.com/api/";
    //var baseUrl = "http://localhost:5000/api/";
    //var baseUrl = "http://ccp.vip56.cn/api/";
    //var baseUrl = "http://capacitycloud-web-dev.chinacloudsites.cn/api/";

    module.service('routeService', ["$rootScope", function ($rootScope) {
        return {
            getBaseUrl: function () { return baseUrl; },
            getUrl: function (url, value) {
                var result = Mustache.render(baseUrl + url, value);
                //console.log(result)
                return result;
            },
            getUrlArea: function (url, value) {
                var result = Mustache.render(AreaUrl + url, value);
                //console.log(result)
                return result;
            },

            Manage: {
                Account: {
                    Login: {
                        Url: "accounts/login",
                        Method: "Post"
                    },
                    Register: {
                        Url: "Account/Register",
                        Method: "Post"
                    },
                    Logout: {
                        Url: "accounts/logoff?token={{token}}",
                        Method: "Get"
                    },
                    SetAccountLockoutState: {
                        Url: "Login/SetAccountLockoutState?userId={{userId}}&value={{value}}",
                        Method: "Post"
                    },
                    DeleteAccount: {
                        Url: "Login/DeleteAccount?userId={{userId}}",
                        Method: "Post"
                    },
                },

                WebApiCredential: {
                    GetWebApiCredentials: {
                        Url: "credentials?startIndex={{startIndex}}&count={{count}}",
                        Method: "Get"
                    },
                    AddWebApiCredentials: {
                        Url: "WebApiCredential/AddWebApiCredential",
                        Method: "Post"
                    },
                    RemoveWebApiCredential: {
                        Url: "WebApiCredential/RemoveWebApiCredential?id={{id}}",
                        Method: "Get"
                    }
                },
                roles:{
                    GetRoles: {
                        Url: "roles",
                        Method: "Get"
                    }
                },
                User: {
                    GetUsers: {
                        Url: "users?keyword={{keyword}}&carCode={{carCode}}&startTime={{startTime}}&endTime={{endTime}}&roleId={{roleId}}&state={{state}}&startIndex={{startIndex}}&count={{count}}",
                        Method: "Get"
                    },
                    CreateUser: {
                        Url: "User/CreateUser?email={{email}}&phoneNumber={{phoneNumber}}",
                        Method: "Get"
                    },
                    GetRealNameInfo: {
                        Url: "users/{{user_id}}",
                        Method: "Get"
                    },
                    PutUserInfo: {
                        Url: "User/PutUserInfo",
                        Method: "Post"
                    },
                    PutUserRealNameInfo: {
                        Url: "User/PutUserRealNameInfo",
                        Method: "Post"
                    },
                    PutUserRealNameCertificationStatus: {
                        Url: "users/{{user_id}}",
                        Method: "Put"
                    },
                    Tag: {
                        Url: "users/{{user_id}}/enabled?disabled={{disabled}}",
                        Method:"Get"
                    }
                },
                Storage: {
                    AquireStorageSharedSigniture: {
                        Url: "Storage/AquireStorageSharedSigniture?containerName={{containerName}}&expireTime={{expireTime}}",
                        Method: "Get"
                    }
                },
                Order: {
                    GetOrderList: {
                        Url: "Order/GetOrderList?state={{state}}&startingPlaceCode={{startingPlaceCode}}&destinationCode={{destinationCode}}&carLength={{carLength}}&startIndex={{startIndex}}&count={{count}}",
                        Method: 'Get'
                    },
                    GetSuborderList: {
                        Url: "Order/GetSubordersList?orderId={{orderId}}",
                        Method: 'Get'
                    },
                    DeleteOrder: {
                        Url: "Order/DeleteOrder?orderId={{orderId}}",
                        Method: 'Post'
                    },
                    GetMyOrderList:{
                        Url: "Order/GetMyOrderList?startIndex={{startIndex}}&count={{count}}",
                        Method: 'Get'
                    }
                },
                Area: {
                    provincecode: {
                        Url: "area/city/{{provincecode}}",
                        Method: 'Get'
                    },
                    cityCode: {
                        Url: "area/county/{{citycode}}",
                        Method: 'Get'
                    },
                    Area: {
                        Url: "Area",
                        Method: 'Get'
                    },
                }
            }
        };
    }]);
})();